<style>
 *::-webkit-scrollbar { width: 0 !important}
</style>


<template>
  <div id="salesOrder">

       <Spin size="large" fix v-if="spinShow"></Spin>


    <!-- 根据条件查询 -->
    <div>
      <el-form :inline="true"  class="demo-form-inline" ref="ruleForm">
        <el-form-item label="单据编号">
          <el-input v-model="documentNumber" placeholder="请输入单据编号查询"></el-input>
        </el-form-item>
        <el-form-item label="商品信息">
          <el-input v-model="productName" placeholder="请输入商品信息查询"></el-input>
        </el-form-item>
        <el-form-item label=" 单据日期 ">
          <el-date-picker
            v-model="begintime"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="['12:00:00']"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <!-- <el-button type="primary" @click="getSalesOrderList">查询</el-button> -->
             <el-button type="primary" plain   @click="getSalesOrderList">查询</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- table展示 -->
    <div>
      <div style="margin-top: 20px;">
        <!-- <el-button type="primary" @click="addSalesOrder1" ><Icon type="md-add" /> 添加</el-button> -->
        <el-button type="primary" plain   @click="addSalesOrder1"><Icon type="md-add" /> 添加</el-button>

        <el-dropdown split-button type="primary" style="padding-left:20px" v-show="this.xlk">
          批量操作
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <Icon type="ivu-icon ivu-icon-ios-checkmark-circle-outline"/>
              <span @click="shenhe">审核</span>
            </el-dropdown-item>
         
             <el-dropdown-item>
            <Icon type="ios-add" />
               <span @click="addSalesOrder2">继续添加</span>
            </el-dropdown-item>
             
          </el-dropdown-menu>
        </el-dropdown>
      </div>

      <br>
      <Table
        border
        ref="selection"
        :columns="columns4"
        :data="data1"
        @on-selection-change="select2"
      >
        <template slot-scope="{ row, index }" slot="action">
          <!-- <Button type="info" size="large" @click="findSalesOrderByDCNum(row)">查看</Button> -->

           <el-button type="primary" plain   @click="findSalesOrderByDCNum(row)">查看</el-button>
        </template>

       

        <template slot-scope="scope" slot="status">
          <el-tag :type="scope.row.erpState.stateName==='审核'? 'primary':'danger'" >
            {{scope.row.erpState.stateName=='审核'?"审核":"未审核"}}
            </el-tag>
        </template>
      </Table>
    </div>
    <br>

    <div style="float:right">
      <Page
        :total="dataCount"
        :page-size="pageSize"
        @on-change="changepage"
        @on-page-size-change="_nowPageSize"
        show-elevator
      />
    </div>

    <!-- 添加销售订单的modal -->
    <div>
      <Modal v-model="addSalesOrder" title="Add" @on-ok="ok" @on-cancel="cancel" width="1355">
        <div>
          <el-form :inline="true" :model="ErpSalesorder" class="demo-form-inline">

            <el-form-item label="销售人员:">
                    <el-input v-model="this.userName" disabled=""></el-input>
            </el-form-item>

           
             <el-form-item label="单据日期:">
              <div class="block">
                <el-date-picker v-model="this.addForm.createDate" type="datetime" placeholder="选择日期时间"  
                format="yyyy 年 MM 月 dd 日  HH时 mm分  ss秒"
                value-format="yyyy-MM-dd HH:mm:ss"
                ></el-date-picker>
              </div>
            </el-form-item>


             <el-form-item label="*客户:">
              <el-select v-model="ErpSalesorder.clientName" placeholder="客户姓名">
                <el-option v-for="item in kehu" :label='item.clientName' :value='item.clientName'></el-option>
              </el-select>
            </el-form-item>

 
               <el-form-item label="收货地址:">
                    <el-input v-model="ErpSalesorder.salesLocation" ></el-input>
            </el-form-item>
         <br>

            <el-form-item label="单据编号:">
              <el-input v-model="this.documentNumber2"  disabled=""></el-input>
            </el-form-item>   

             <el-form-item label="银行卡号:">
              <el-select  placeholder="请选择银行卡号:"  v-model="ErpSalesorder.types" @change="selectType">

              <el-option v-for="item in ErpSettlementaccount" :label="item.accountNumber" :value="item.id" ></el-option>
              </el-select>
            </el-form-item>

             <el-form-item label="开户银行::">
              <el-input v-model="this.SettlementaccountNum"  disabled=""></el-input>
            </el-form-item> 
          </el-form>

<br>


          <!-- 添加销售订单具体内容 -->
          <el-form ref="ErpSalescontent" :model="ErpSalescontent" label-width="100px">
            <div style="border-left: 4px solid #39a9ff;padding-left: 8px;line-height: initial;font-size: initial;">
              <h4>商品详情</h4>
            </div>
            <br><br>
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="商品类型:" >
                    <el-select v-model="ErpSalescontent.type" placeholder="请选择商品类型" @change="selectGet">
                      <el-option v-for="item in styleComm" :label="item.classificationName" :value="item.id" ></el-option>
                    </el-select>

                    <!-- 13 -->
                  </el-form-item>
                </el-col>

                <el-col :span="7">
                  <el-form-item label="商品名称:" >
                    <el-select v-model="ErpSalescontent.productName" placeholder="请选择商品"  @change="selectGet2">
                        <el-option v-for="item in alreadystorageList" :label="item.productName" :value="item.productName" ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>

                 <el-col :span="7">
                  <el-form-item label="商品数量:" >
                    <el-input v-model="ErpSalescontent.number" ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <!-- 第二行 -->
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="商品型号:" >
                    <el-input v-model="ErpSalescontent.model" disabled=""></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="商品单位:" >
                    <el-input v-model="ErpSalescontent.unit" disabled=""></el-input>
                  </el-form-item>
                </el-col>
              
                <el-col :span="7">
                  <el-form-item label="最低售价:" >
                    <el-input v-model="ErpSalescontent.lowestPrice"  disabled=""></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="仓库所在地:" >
                    <el-select v-model="ErpSalescontent.wid" placeholder="仓库" disabled="">
                        <el-option :label="ErpSalescontent.resName" :value="ErpSalescontent.wid" ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="销售价格:" >
                    <el-input v-model="ErpSalescontent.unitPrice"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="市场价格" >
                    <el-input v-model="ErpSalescontent.sellingPrice" disabled=""></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
          </el-form>
        </div>
      </Modal>
    </div>




        




    <!-- 继续添加销售订单的具体内容 -->
        <!-- 添加销售订单具体内容的modal -->
    <div>
      <Modal v-model="addSalesOrderContent" title="Add" @on-ok="addSalesOrderOK" @on-cancel="addSalesOrdercancal" width="1355">
        <div>
          <el-form :inline="true" :model="ErpSalesorder" class="demo-form-inline">

            <el-form-item label="销售人员:">
                    <el-input v-model="this.salesOrderById.operator" disabled=""></el-input>
            </el-form-item>

           
             <el-form-item label="单据日期:">
              <div class="block">
                <el-date-picker v-model="this.salesOrderById.documentDate" type="datetime" placeholder="选择日期时间"  
                format="yyyy 年 MM 月 dd 日  HH时 mm分  ss秒"
                value-format="yyyy-MM-dd HH:mm:ss"
                @on-change="this.salesOrderById.documentDate=$event"
                time-zone="GMT+8"

                ></el-date-picker>
              </div>
            </el-form-item>


             <el-form-item label="*客户:">
      
                   <el-input v-model="this.salesOrderById.clientName" disabled=""></el-input>
        
            </el-form-item>

            <el-form-item label="单据编号:">
              <el-input v-model="this.salesOrderById.documentNumber"  disabled=""></el-input>
            </el-form-item>   

          </el-form>

<br>


          <!-- 添加销售订单具体内容 -->
          <el-form ref="ErpSalescontent" :model="ErpSalescontent" label-width="100px">
            <div style="border-left: 4px solid #39a9ff;padding-left: 8px;line-height: initial;font-size: initial;">
              <h4>商品详情</h4>
            </div>
            <br><br>
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="商品类型:" >
                    <el-select v-model="ErpSalescontent.type" placeholder="请选择商品类型" @change="selectGet">
                      <el-option v-for="item in styleComm" :label="item.classificationName" :value="item.id" ></el-option>
                    </el-select>

                    <!-- 13 -->
                  </el-form-item>
                </el-col>

                <el-col :span="7">
                  <el-form-item label="商品名称:" >
                    <el-select v-model="ErpSalescontent.productName" placeholder="请选择商品"  @change="selectGet2">
                        <el-option v-for="item in alreadystorageList" :label="item.productName" :value="item.productName" ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>

                <el-col :span="7">
                  <el-form-item label="商品条码:" >
                    <el-input v-model="ErpSalescontent.barCode"  disabled=""></el-input>
                  </el-form-item>
                </el-col>
              </el-row>

              <!-- 第二行 -->
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="商品型号:" >
                    <el-input v-model="ErpSalescontent.model" disabled=""></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="商品单位:" >
                    <el-input v-model="ErpSalescontent.unit" disabled=""></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="商品数量:" >
                    <el-input v-model="ErpSalescontent.number" ></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="7">
                  <el-form-item label="仓库所在地:" >
                    <el-select v-model="ErpSalescontent.wid" placeholder="仓库" disabled="">
                        <el-option :label="ErpSalescontent.resName" :value="ErpSalescontent.wid" ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="销售价格:" >
                    <el-input v-model="ErpSalescontent.unitPrice"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label="序列号:" >
                    <el-input v-model="ErpSalescontent.productNumber" disabled=""></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
          </el-form>
        </div>
      </Modal>
    </div>

     <Modal
        v-model="delmodal"
        title="警告"
        
        @on-ok="delSalesOrderContentByid">
        <p>确定要删除吗?</p>
    </Modal>


    <!-- 根据订单编号查看 -->
    <Modal v-model="findSalseDMNumContent" title="详情" @on-ok="okDM" @on-cancel="cancelDM" width="1340">
      <Table border ref="selection" :columns="columns5" :data="DMNumList" height="350" >
        <template slot-scope="{ row, index }" slot="resName">{{row.erpWarehouseinformation.resName}}</template>

         <template slot-scope="{ row, index }" slot="upd">
            <!-- <Button type="info" size="large" @click="preUpdSalesOById(row)">修改</Button> -->

            <el-button type="primary" icon="el-icon-edit" circle   @click="preUpdSalesOById(row)"></el-button>
         </template>

          <template slot-scope="{ row, index }" slot="del">
            <!-- <Button type="info" size="large" @click="predelSalesOrderContentByid(row)">删除</Button> -->

             <el-button type="danger" icon="el-icon-delete" circle  @click="predelSalesOrderContentByid(row)"></el-button>
         </template>
      </Table>
    </Modal>


    <!-- 修改的弹出框 -->
     <Modal
        width="1000"
        v-model="updS"
        title="修改"
        @on-ok="updSalesOById"
        >

       <el-form :inline="true" :model="SalesOrderContent2" class="demo-form-inline">
         <el-form-item label="单据编号:">
              <el-input v-model="SalesOrderContent2.documentNumber"  disabled=""></el-input>
            </el-form-item> 

                        
               <el-form-item label="仓库:">
              <el-input v-model="SalesOrderContent2.resName"  disabled=""></el-input>
            </el-form-item> 

            <el-form-item label="id:">
                    <el-input v-model="SalesOrderContent2.id" disabled=""></el-input>
            </el-form-item>



              
         <br>

          <el-form-item label="商品名称:">
                    <el-input v-model="SalesOrderContent2.productName" disabled=""></el-input>
            </el-form-item>
         

             <el-form-item label="数量:">
              <el-input v-model="SalesOrderContent2.number"  ></el-input>
            </el-form-item> 

            <el-form-item label="单价:">
              <el-input v-model="SalesOrderContent2.unitPrice"  ></el-input>
            </el-form-item>   
       </el-form>



    </Modal>


  </div>
</template>


<script>
import axios from "axios";
export default {
  data() {
    return { 
      //修改
      SalesOrderContent2:{
       
      },

      //修改对话框
      updS:false,

      //对话框
      delmodal:false,

      //保存删除的id
      delId:"",

      //接收根据id查询的salseOrder
      salesOrderById:{},


      //封装了已经入库的内容
      alreadystorageList:[],

      //销售订单的对象
      ErpSalesorder:{},

      //销售订单内容的数组
      ErpSalescontentArr:[
        
      ],



    
      //默认时间
    addForm:{
        createDate:new Date()
      },


        //客户list
        kehu:[],

        //刷新
        spinShow:true,


      pageSize: 5, //每页显示多少条
      dataCount: 0, //总条数
      pageCurrent: 1, //当前页,
      width: 100,

      // 分页的条件
      productName: "",
      documentNumber: "",
      begintime: [],

    // 销售人员
      userName:"",

      //商品类型
      styleComm: [],

      //单据编号
      documentNumber2:"",

      // table多选框的值
      tableSelection: [],

      //隐藏的下拉框
      xlk: false,

      //购房人基本信息属性
      ErpSalescontent: {
        // purPeoList: [
          // {
            erpWarehouseinformation:{
            
            },
            resName:"",
            documentNumber: "",
            productName: "",
            wid: "",
            unit: "",
            model: "",
            type: "",
            productNumber: "",
            number: "",
            barCode: "",
            unitPrice: ""
          // }
        // ]
      },

      // 88888
      columns5: [
        {
            title:"#",
            key:"id",
            align:"center",
        },
         {
          title: "单据编号",
          key: "documentNumber",
            align:"center",
        },
        {
          title:"序列号",
          key:"productNumber",
            align:"center",
        },
        {
          title: "商品名称",
          key: "productName",
            align:"center",
        },
      
       
        {
          title:"数量",
          key:"number",
            align:"center",
        },
        {
          title:"单价",
          key:"unitPrice",
            align:"center",
        },
         {
          title:"总价",
          key:"countPrice",
            align:"center",
        },
         {
          title: "仓库",
          slot: "resName",
            align:"center",
        },
        {
          title:"修改",
          slot:"upd",
            align:"center",
        },
         {
          title:"删除",
          slot:"del",
            align:"center",
        }
       
      ],
      DMNumList: [],

      columns4: [
        {
          type: "selection",
          width: 60,
          align: "center"
        },
        {
          title: "#",
          key: "id",
            align:"center",
        },
        {
          title: "客户名称",
          key: "clientName",
            align:"center",
        },
          {
          title: "收货地址",
          key: "salesLocation",
            align:"center",
        },
        {
          title: "单据编号",
          key: "documentNumber",
            align:"center",
        },
        {
          title: "商品信息",
          key: "productName",
            align:"center",
        },
        {
          title: "单据日期",
          key: "documentDate",
            align:"center",
        },
        {
          title: "操作员",
          key: "operator",
            align:"center",
        },
        {
          title: "金额合计",
          key: "totalAmount",
            align:"center",
        },
        {
          title: "状态",
          slot: "status",
            align:"center",
        },
        // {
        //   title: "状态2(零售/批发)",
        //   slot: "status3"
        // },
        {
          title: "operate",
          slot: "action",
            align:"center",
        }
      ],
      data1: [],
      addSalesOrder: false,
      addSalesOrderContent: false,
      findSalseDMNumContent: false,

      //结算账户的卡
      ErpSettlementaccount:[],
      SettlementaccountNum:"",

     
      value1: "",
      value2: "",
      solesOrder: {}
    };
  },

  // 挂载
  created() {
    this.getSalesOrderList();
    this.getErpCustomerinformationList();
    this.getCommodityStyleList2();
    this.findErpSettlementaccountList();
   
   
  },

  methods: {

//支付类型下拉框选中事件
    selectType(value){
        console.log(value)
        for(var i=0;i<this.ErpSettlementaccount.length;i++){
          if(value==this.ErpSettlementaccount[i].id){
              this.SettlementaccountNum=this.ErpSettlementaccount[i].accountName
          }
        }
        console.log(this.SettlementaccountNum)
    },


    //查询所以结算账户的卡
    findErpSettlementaccountList(){
      axios.post("//localhost:8082/salesOrder/findErpSettlementaccountList").then(res=>{
        this.ErpSettlementaccount=res.data;
           console.log("00000000000000000000000")
        console.log(this.ErpSettlementaccount)
      })

    },

    //查找商品类型List
       getCommodityStyleList2(){
        axios
        .post(
          "//localhost:8082/ErpCommoditystyle/getCommodityStyleList"
        )
        .then(res => {
          console.log(res.data)
          this.styleComm=res.data;
          console.log(this.styleComm)
        });
    },

    
//点击下拉框的值  触发事件  获取已经入库的list
selectGet(vId){
      let obj = {};
      obj=this.styleComm.find((item)=>{
          return item.id===vId
      })
      console.log(obj.id)
      axios.post("//localhost:8082/Alreadystorage/getAlreadystorageListByType?type="+obj.id).then(
        res=>{
            this.alreadystorageList=res.data;
            console.log(this.alreadystorageList)
        }
      )
},

//点击下拉框的值  触发事件  将一条数据赋值给各个input
selectGet2(name){

      let obj = {};
      //循环判断
      obj=this.alreadystorageList.find((item)=>{
          return item.productName===name
      })
      //赋值
        this.ErpSalescontent.resName=obj.erpWarehouseinformation.resName
        this.ErpSalescontent.wid=obj.wid
        this.ErpSalescontent.documentNumber=obj.documentNumber
          this.ErpSalescontent.unit=obj.unit
            this.ErpSalescontent.model=obj.model
              this.ErpSalescontent.productNumber=obj.productNumber
               this.ErpSalescontent.number=obj.num
                this.ErpSalescontent.barCode=obj.barCode
                    this.ErpSalescontent.unitPrice=obj.sellingPrice
                    this.ErpSalescontent.sellingPrice=obj.sellingPrice
                     this.ErpSalescontent.lowestPrice=obj.lowestPrice
                     this.ErpSalescontent.supplier=obj.supplier

                     console.log("111")
                     console.log(this.ErpSalescontent)
      
},




    //查询客户信息
    getErpCustomerinformationList(){
        axios
        .post(
          "//localhost:8082/ErpCustomerinformation/ErpCustomerinformationList"
        )
        .then(res => {
          console.log(res.data+"--------------------")
          this.kehu=res.data;
          console.log(this.kehu)
        });
    },



    
    // 查找所以销售订单的信息   // 分页
    getSalesOrderList() {
      axios
        .post(
          "//localhost:8082/salesOrder/getPageBySalesOrder1?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            this.pageCurrent
        )
        .then(res => {
          console.log(res.data);
          this.dataCount = res.data.countTotal;
          this.data1 = res.data.list;
          console.log(this.begintime + "123");
          //当从数据库获取完毕  关闭加载特效
          this.spinShow=false;
          // this.begintime = "";
        });
    },

    // 根据单据编号查询
    findSalesOrderByDCNum(row) {
      axios
        .get(
          "http://localhost:8082/salesOrderContent/getSalesOrderByDCNum?documentNumber=" +
            row.documentNumber
        )
        .then(res => {
          this.DMNumList = res.data;
          console.log(this.DMNumList)
          this.findSalseDMNumContent = true;
        });
    },

    //点击这个,即可换页数
    changepage(index) {
      axios
        .get(
          "http://localhost:8082/salesOrder/getPageBySalesOrder1?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime +
            "&pageSize=" +
            this.pageSize +
            "&pageCurrent=" +
            index
        )
        .then(response => {
          this.dataCount = response.data.countTotal;
          this.data1 = response.data.list;
        });
    },

    //每页显示的数据条数
    _nowPageSize(index) {
      //实时获取当前需要显示的条数
      this.pageSize = index;
    },


    // 添加销售订单的内容  第一条
    addSalesOrder1(){
      //当点击一次添加   自动更新一次订单编号
      this.documentNumber2='AZ'+this.getProjectNum()+Math.floor(Math.random() * 10000) ;
      //从session中获取session
      this.userName = sessionStorage.getItem("user");
      //是model展示出来   默认false
      this.addSalesOrder=true;
       this.ErpSalescontent = {}
       this.ErpSalesorder={}
    },


    //继续添加销售订单的内容  第二条 第三条等
    addSalesOrder2(){
      console.log(this.tableSelection[0])
        if(this.tableSelection.length==1){
          var id="";
          id=this.tableSelection[0].id
          //根据id查询出
        axios.post("http://localhost:8082/salesOrder/findSalesOrderById2?id="+id).then(res=>{
              //根据id查询出来销售订单  赋值
              this.salesOrderById=res.data;
            
        })


          //打开弹框
        this.addSalesOrderContent=true;
        }else{
           this.$notify.info({
          title: '消息',
          message: '请选择一条内容进行添加'
        });
        }


       
    },

    onSubmit() {
      axios
        .post(
          "http://localhost:8082/salesOrder/aaa?documentNumber=" +
            this.documentNumber +
            "&productName=" +
            this.productName +
            "&time=" +
            this.begintime
        )
        .then(response => {
          console.log(this.begintime);
        });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //新增购房人基本信息
    addBuyerInformation() {
      const that = this;
      that.basicInformation.purPeoList.push({});
    },
    //删除购房人基本信息
    removeRow(index) {
      if (index >= 0) {
        this.basicInformation.purPeoList.splice(index, 1);
      }
    },

    // 添加销售订单和销售订单的
    ok() {
      this.ErpSalesorder.operator=this.userName;
      this.ErpSalesorder.documentNumber=this.documentNumber2;
      this.ErpSalesorder.documentDate=this.addForm.createDate;

//转换时间格式
      var d=this.addForm.createDate;
      
var datetime=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();

    console.log("13123")
     console.log(datetime)
        axios.post("//localhost:8082/salesOrder/addSalesOrderAndContent?salesPeople="+this.userName+"&documentDate="+datetime
        +"&salesLocation="+this.ErpSalesorder.salesLocation+"&documentNumber="+this.documentNumber2+"&types="+this.ErpSalesorder.types
        +"&clientName="+this.ErpSalesorder.clientName, this.ErpSalescontent).then(res=>{
          console.log("123")
          console.log(res.data)
          if(res.data=="1"){
                //刷新
        this.getSalesOrderList();
         this.$notify({
          title: '成功',
          message: '恭喜你,添加成功666',
          type: 'success'
        });
          }else if(res.data="6"){
             this.$notify({
          title: '警告',
          message: '内容不能为空!',
          type: 'warning' 
          });
          }else if(res.data=="3"){
                 this.$notify({
          title: '警告',
          message: '订单号重复,请重新添加!',
          type: 'warning' 
          });
          }
        else{
             this.$notify({
          title: '警告',
          message: '商品数量不足或商品低于最低价格无法添加!',
          type: 'warning'
        });
          }
        
      })

      
    },

        cancel() {
        // this.$notify({
        //   title: '警告',
        //   message: '已取消添加',
        //   type: 'warning'
        // });
    },












//继续添加销售订单的商品内容  
    addSalesOrderOK(){
        axios.post("//localhost:8082/salesOrder/addSalesOrderAndContent2?documentNumber="+this.salesOrderById.documentNumber,this.ErpSalescontent).then(res=>{
        if(res.data=="1"){
                //刷新
        this.getSalesOrderList();
         this.$notify({
          title: '成功',
          message: '恭喜你,再次添加成功',
          type: 'success'
        });
          }else if(res.data=="2"){
        this.$notify({
          title: '警告',
          message: '已经审核无法添加!',
          type: 'warning'
        });
          } else{
             this.$notify({
          title: '警告',
          message: '商品数量不足或商品低于最低销售价格无法添加!',
          type: 'warning'
        });
          }
        })
       
    },



  //取消按钮
    addSalesOrdercancal(){
       this.$notify({
          title: '警告',
          message: '已取消添加',
          type: 'warning'
        });
    },


   





    //查看销售订单具体内容   确定按钮
    okDM(){
        this.$notify({
          title: '成功',
          message: '恭喜你,查看成功',
          type: 'success'
        });
    },
    //查看销售订单   取消按钮
    cancelDM(){
      // this.$notify({
      //     title: '警告',
      //     message: '已取消查看',
      //     type: 'warning'
      //   });
    },


 
    // 重置
    resetForm() {
      this.documentNumber = "";
      this.begintime = [];
      this.productName = "";
    },

    // 当选中的时候触发   没有选中不触发
    select2(rows) {
      this.tableSelection = rows;
      console.log(this.tableSelection);
      this.xlk = true;
      if (this.tableSelection.length == 0) {
        this.xlk = false;
      }
    },

    // 审核
    shenhe() {
      if(this.tableSelection.length==1){
    //创建一个数组
      let ids = [];
      //赋值
      this.tableSelection.forEach(function(e) {
        ids.push(e.id);
      });
    
       this.$confirm('确定启用吗?, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //当点击确定  开始加载特效
           this.spinShow=true;
           //跨域
            axios.post("http://localhost:8082/salesOrder/shenhe?id="+ ids[0])
            .then(res => {
              if(res.data==1){
          //成功的提示
                        this.$notify({
                    title: '审核成功',
                    message: '恭喜你审核成功',
                    type: 'success'
                  });
              }else{
            
          this.$notify({
          title: '警告',
          message: '审核之前请认真查看该订单的商品!',
          type: 'warning'
        });
              }
             
        //刷新
            this.getSalesOrderList();   
            //当启用成功以后  结束加载特效
             this.spinShow=false;     
            });

  this.getSalesOrderList();
        }).catch(() => {
          this.$notify({
          title: '取消审核',
          message: '恭喜你取消审核成功',
          type: 'warning'
        });        
        });
        }else{
           this.$notify.info({
          title: '消息',
          message: '请选择一条内容进行添加'
        });
        }
        this.xlk=false;
      
    },



      //反审核
        fanshenhe() {
        if(this.tableSelection.length==1){
 //创建一个数组
      let ids = [];
      //赋值
      this.tableSelection.forEach(function(e) {
        ids.push(e.id);
      });
      console.log(ids);
       this.$confirm('确定禁用吗?, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //当点击确定  开始加载特效
           this.spinShow=true;
           //跨域
            axios.post("http://localhost:8082/salesOrder/fanshenhe?id="+ ids[0])
            .then(res => {
              //成功的提示
               this.$notify({
          title: '禁用成功',
          message: '恭喜你禁用成功',
          type: 'success'
        });
        //刷新
            this.getSalesOrderList();   
            //当启用成功以后  结束加载特效
             this.spinShow=false;     
            });
  this.getSalesOrderList();
        }).catch(() => {
          this.$notify({
          title: '取消审核',
          message: '恭喜你取消反审核成功',
          type: 'warning'
        });        
        });
              }else{
  this.$notify.info({
          title: '消息',
          message: '请选择一条内容进行添加'
        });
              }




     
    },


    //生成单据编号
    // 获取当前日期的方法
	    getProjectNum () {
      const projectTime = new Date() // 当前中国标准时间
      const Year = projectTime.getFullYear() // 获取当前年份 支持IE和火狐浏览器.
      const Month = projectTime.getMonth() + 1 // 获取中国区月份
      const Day = projectTime.getDate() // 获取几号
      var CurrentDate = Year
      if (Month >= 10) { // 判断月份和几号是否大于10或者小于10
        CurrentDate += Month
      } else {
        CurrentDate += '0' + Month
      }
      if (Day >= 10) {
        CurrentDate += Day
      } else {
        CurrentDate += '0' + Day
      }
      return CurrentDate+1
},


    //预删除
    predelSalesOrderContentByid(row){
        this.delId=row.id;
        this.delmodal=true;

      // axios.post("http://localhost:8082/salesOrderContent/delSalesOrderContentById?id="+row.id).then(res=>{
      //   console.log(row)
        
      // })
    },

//删除销售订单的商品
    delSalesOrderContentByid(){

      axios.post("http://localhost:8082/salesOrderContent/delSalesOrderContentById?id="+this.delId).then(res=>{
        // console.log(row)
        this.spinShow=true;
      this.findSalseDMNumContent=false;
       this.getSalesOrderList();
       this.spinShow=false;
        

        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success'
            });
      })
    },


    //预修改
    preUpdSalesOById(row){
      this.SalesOrderContent2=row;
      this.SalesOrderContent2.resName=row.erpWarehouseinformation.resName
      this.findSalseDMNumContent=false;
      this.updS=true;
    
      
    },


    //修改
    updSalesOById(){
       axios.post("http://localhost:8082/salesOrderContent/updSalesOrderContentById",this.SalesOrderContent2).then(res=>{
          if(res.data=="1"){
          this.$notify({
          title: '成功',
          message: '修改成功',
          type: 'success'
          
        });
        this.getSalesOrderList();
            }else{
        this.$notify.error({
          title: '错误',
          message: '修改失败,价格偏低或库存不足'
        });
          }
       })
    }





  }
};
</script>
